;; macros originally from https://notabug.org/eq/testscm

(define-syntax test
  (syntax-rules ()
    ((test name success text)
     (begin
       (display (format #f
                        "~a: ~a\x1b[39m ~a\n"
                        name
                        (if success "\x1b[32mSUCCESS" "\x1b[31mFAILURE")
                        text))
       (list (if success 0 1) 1)))
    ((test name success input result expected)
     (test name success
           (if success
               (format #f "~a -> ~a" input result)
               (format #f "~a -> ~a (expected ~a)" input result expected))))
    ((test name input result expected)
     (test name (equal? expected result) input result expected))))

(define-syntax test-group
  (syntax-rules ()
    ((test-group name (test tname args ...) ...)
     (let
       ((count
          (map (lambda (x) (apply + x))
               (map list
                    (test (string-append name tname) args ...) ...))))
       (when (> (string-length name) 0)
         (display (format #f "~a: ~a out of ~a tests failed\n"
                          name
                          (car count)
                          (cadr count))))
       count))))

(define-syntax test-func
  (syntax-rules ()
    ((test-func name f expected)
     (test name (equal? f expected) (quote f) f expected))))

(add-to-load-path (dirname (current-filename)))
(load-from-path "test/vec.scm")

(test-group
  "/"
  (test-vec "vec.scm/"))
